<template>
  <transition name="fade-slide" @after-leave="beforeClose">
    <div class="c-message-box__wrapper" v-show="visible" @click="cancel">
      <div class="c-message-box__content">
        <div class="c-message-box__title">
          {{ title }}
          <img src="@/assets/images/icon-close.png" v-if="showCloseBtn" @click.stop="cancel">
        </div>
        <div class="c-message-box__message">{{ message }}</div>
        <div class="c-message-box__btns">
          <i-button type="info" v-if="showCancelBtn" @click.stop="cancel">{{ cancelBtnText }}</i-button>
          <i-button type="primary" @click.stop="confirm">{{ confirmBtnText }}</i-button>
        </div>
      </div>
    </div>
  </transition>
</template>
<script type="text/babel">
export default {
  data() {
    return {
      visible: false,
      title: '提示',
      message: '',
      confirmBtnText: '确定',
      showCancelBtn: true,
      cancelBtnText: '取消',
      showCloseBtn: true,
    }
  },
  computed: {},
  methods: {
    confirm() {
      this.visible = false
      this.resolve();
    },
    cancel() {
      this.visible = false
      this.reject()
    },
    beforeClose() {
      this.$emit('close');
    }
  },
  created() {
  },
  watch: {
    visible() {
    }
  }
}
</script>

<style scoped lang="scss">
@import "@/assets/style/mixin";
.c-message-box {
  &__wrapper {
    background: rgba(0, 0, 0, 0.3);
    position: fixed;
    z-index: 9999;
    height: 100vh;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
  }
  &__content {
    position: fixed;
    top: 40%;
    transform: translateY(-40%);
    z-index: 1001;
    width: 400px;
    padding: 20px;
    background: #fff;
    border-radius: 12px;
    line-height: normal;
  }
  &__title {
    @include flex_between();
    font-size: 18px;
    font-weight: bold;
    padding-left: 8px;
    position: relative;
    &::before {
      content: "";
      position: absolute;
      left: 0;
      width: 4px;
      height: 18px;
      @include background_color();
      top: 50%;
      transform: translateY(-50%);
    }
    img {
      width: 24px;
      height: 24px;
      cursor: pointer;
    }
  }
  &__message {
    padding: 26px 0;
    text-align: center;
    margin-bottom: 10px;
    font-size: 18px;
    font-weight: bold;
  }
  &__btns {
    @include flex-center();
    .ivu-btn {
      width: 96px;
      margin: 0 5px;
    }
  }
}

.fade-slide-enter-active, .fade-slide-leave-active {
  transition: all 0.2s ease;
}
.fade-slide-enter-active .c-message-box__content {
  transition: opacity 0.1s ease, transform 0.2s ease;
}
.fade-slide-leave-active .c-message-box__content {
  transition: opacity 0.1s ease, transform 0.2s ease;
}
//离开初始
.fade-slide-enter, .fade-slide-leave-to {
  opacity: 0;
}
.fade-slide-enter .c-message-box__content, .fade-slide-leave-to .c-message-box__content {
  transform: translateY(-100%);
}
</style>
